
import moment from 'moment'

// 将“2020-01-01” 转化为 2020年01月01日
const setDate = dateStr => {
  if (dateStr) {
    moment.locale('zh-cn')
    const date = moment(dateStr).format('ll')
    return date
  }
}

// 将日期转换为距离今天的时间差
const timeDiff = (date) => {
  if (date) {
    const oldDate = moment(date).format('YYYY-MM-DD')
    const newDate = moment(new Date()).format('YYYY-MM-DD')
    const diff = moment(newDate).diff(oldDate, 'day')
    return `${diff}`
  }
}

// 将“09:00:00”转换为“09:00”
const setTime = (time) => {
  return moment(time, 'HH:mm:ss').format("HH:mm");
}

export {
  setDate,
  timeDiff,
  setTime,
}